package learn.advance.annotation.demo;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Method;

public class Test {
    public static void main(String[] args) throws IOException {
        Calculator c=new Calculator();

        Class cls=c.getClass();

        Method[] methods=cls.getMethods();
        int num=0;

        BufferedWriter bw=new BufferedWriter(new FileWriter("bug.txt"));

        for(Method method:methods){
            if(method.isAnnotationPresent(Check.class)){
                try{
                    method.invoke(c);
                }catch (Exception e){
                    num++;
                    bw.write("异方法："+method.getName());
                    bw.newLine();
                    bw.write("异常的名称："+e.getCause().getClass().getSimpleName());
                    bw.newLine();
                    bw.write("异常的原因："+e.getCause().getMessage());
                    bw.newLine();
                    bw.write("------------------------");
                    bw.newLine();

                }
            }
        }

        bw.flush();
        bw.close();

    }
}